﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using HotelManagement.Class;

namespace HotelManagement
{
    public partial class ConfirmAdditionalGuestInformation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int bookingID = Convert.ToInt32(Request.QueryString["BookingID"]);
                BookingInfo b = BookingAndRoomAvailabilityDBManager.GetBookingInfo(bookingID);
                lblBookingID.Text = bookingID.ToString();

                //int guestID = Convert.ToInt32(Request.QueryString["GuestID"]);
                //Guest g1 = BookingAndRoomAvailabilityDBManager.GetBookingInfoByGuestId(guestID);
                Room r = BookingAndRoomAvailabilityDBManager.GetRoomInfoByBookingId(bookingID);


                DateTime arrivalDateOnly = b.ArrivalDate.Date;
                string arrivalDate = arrivalDateOnly.ToString("dd/MM/yyyy");
                lblArrivalDate.Text = arrivalDate;

                lblArrivalTime.Text = b.ArrivalTime.ToString();

                DateTime departDateOnly = b.DepartDate.Date;
                string departDate = departDateOnly.ToString("dd/MM/yyyy");
                lblDepartDate.Text = departDate;

                lblDepartTime.Text = b.DepartTime.ToString();

                lblRetrieveNight.Text = b.NumOfNight.ToString();
                lblAdult.Text = b.NumOfAdult.ToString();
                lblChildren.Text = b.NumOfChildren.ToString();
                lblRoom.Text = b.RoomNum.ToString();
                lblRoomType.Text = r.TypeOfRoom;

                lblRemarks.Text = b.Remarks;
                lblArea.Text = b.Area;
                lblPayment.Text = b.PaymentMode;

                Guest g = BookingAndRoomAvailabilityDBManager.GetGuestInfoByBookingId(bookingID);
                lblRetrieveGuestID.Text = g.GuestID.ToString();
                lblRetrieveTitle.Text = g.Title;
                lblRetrieveFirstName.Text = g.FirstName;
                lblRetrieveLastName.Text = g.LastName;
                lblGender.Text = g.Gender;
                
                DateTime dobOnly=g.DOB.Date;
                string dob=dobOnly.ToString("dd/MM/yyyy");
                lblDOB.Text = dob;

                lblEmail.Text = g.Email;
                lblMobile.Text = g.MobileNum.ToString();
                lblHome.Text = g.HomeNum.ToString();
                lblAddress.Text = g.Address;
                lblCity.Text = g.City;
                lblState.Text = g.State;
                lblZip.Text = g.ZipCode.ToString();
                lblCountry.Text = g.Country;

               // int guestID=g.GuestID;
                CreditCard c = BookingAndRoomAvailabilityDBManager.GetCreditCardInfoByGuestID(g.GuestID);
                lblCardHolderName.Text = c.CardHolderName;
                lblType.Text = c.Type;
                lblCardNumber.Text = c.CardNum;
                
                DateTime expiryDateOnly=c.ExpiryDate.Date;
                string expiry=expiryDateOnly.ToString("dd/MM/yyyy");
                lblExpiry.Text = expiry;
                
                
            }
        }

        protected void btnGenerateInvoice_Click(object sender, EventArgs e)
        {
            string itemUsed = tbxItemUsed.Text;
            double extraCharges = Convert.ToDouble(tbxExtraCharges.Text);
            string comment = tbxComment.Text;
                        
            int bookingId=Convert.ToInt32(lblBookingID.Text);
            string cardNum=lblCardNumber.Text;
            Invoice i = new Invoice(bookingId, itemUsed, extraCharges, comment, cardNum);

            string queryString = "guestId=" + lblRetrieveGuestID.Text;
            queryString += "&" + "title=" + lblRetrieveTitle.Text;
            queryString += "&" + "firstName=" + lblRetrieveFirstName.Text;
            queryString += "&" + "lastName=" + lblRetrieveLastName.Text;
            queryString += "&" + "gender=" + lblGender.Text;
            queryString += "&" + "dob=" + lblDOB.Text;
            queryString += "&" + "email=" + lblEmail.Text;
            queryString += "&" + "mobileNum=" + lblMobile.Text;
            queryString += "&" + "homeNum=" + lblHome.Text;
            queryString += "&" + "address=" + lblAddress.Text;
            queryString += "&" + "city=" + lblCity.Text;
            queryString += "&" + "state=" + lblState.Text;
            queryString += "&" + "zipCode=" + lblZip.Text;
            queryString += "&" + "country=" + lblCountry.Text;
            queryString += "&" + "itemUsed=" + itemUsed;
            queryString += "&" + "comment=" + comment;
            queryString += "&" + "extraCharges=" + extraCharges;
            queryString += "&" + "arrivalDate=" + lblArrivalDate.Text;
            queryString += "&" + "arrivalTime=" + lblArrivalTime.Text;
            queryString += "&" + "departDate=" + lblDepartDate.Text;
            queryString += "&" + "departTime=" + lblDepartTime.Text;
            queryString += "&" + "numOfNights=" + lblRetrieveNight.Text;
            queryString += "&" + "numOfAdults=" + lblAdult.Text;
            queryString += "&" + "numOfChildren=" + lblChildren.Text;
            queryString += "&" + "roomNum=" + lblRoom.Text;
            queryString += "&" + "roomType=" + lblRoomType.Text;
                       
            queryString += "&" + "remarks=" + lblRemarks.Text;
            queryString += "&" + "bookingId=" + lblBookingID.Text;
            queryString += "&" + "area=" + lblArea.Text;
            queryString += "&" + "paymentOption=" + lblPayment.Text;
            queryString += "&" + "cardHolder=" + lblCardHolderName.Text;
            queryString += "&" + "type=" + lblType.Text;
            queryString += "&" + "cardNum=" + lblCardNumber.Text;
            queryString += "&" + "expiryDate=" + lblExpiry.Text;

            if (BookingAndRoomAvailabilityDBManager.InsertInvoice(i) == 1)
            {
                Server.Transfer("GenerateInvoice.aspx?" + queryString);
             
            }
            else
            {
                lblInvoiceStatus.Text = "Generating Invoice is unsuccessful";
            }
        }
    }
}